<?php

class AjaxController extends Zend_Controller_Action
{
    function init()
    {
        $this->db = Zend_Registry::get("db");
    }
    
    function preDispatch()
    {

    }

	function indexAction()
	{
		echo "Ajax";die;
	}
	
	function removeNewsAction()
	{
		$_SESSION['site']['news'] = '';
	}
	
	function checkVcodeAction()
	{
		$params = $this->_request->getParams();
    	
    	$result = 0;
		
		if($params['cellphone'] && $params['captcha'])
		{
			$mod_cellphone_veri = new Db_Tables_CellphoneVerification();
			$result = $mod_cellphone_veri->CheckVcode($params['cellphone'], $params['captcha']);
		}
		
		$json = array("result" => $result);
    	
    	echo Zend_Json::encode($json); //back to ajax
    	die;
	}
	
	function checkIcodeAction() //图形验证码
	{
		$params = $this->_request->getParams();
    	
    	$result = 0;
		
		if($params['icode'])
		{
			if(strtolower($_SESSION['veri-image']) == strtolower(trim($params['icode'])))
			{
				$result = 1;
			}
		}
		
		$json = array("result" => $result);
    	
    	echo Zend_Json::encode($json); //back to ajax
    	die;
	}
	
	function isCellphoneAvailableAction()
	{
		$params = $this->_request->getParams();
    	
    	$result = 0;
    	$result2 = 0;
		
		
		if($params['cellphone'])
		{
			$mod = new Db_Tables_Members();
			$row = $mod->fetchRow("cellphone='".trim($params['cellphone'])."'");
			
			if(!$row)
			{
				$result = 1;
			}
			
			$mod = new Db_Tables_Agents();
			$row = $mod->fetchRow("cellphone='".trim($params['cellphone'])."'");
			
			if(!$row)
			{
				$result2 = 1;
			}
		}
		
		$json = array("result" => $result, "result2" => $result2);
    	
    	echo Zend_Json::encode($json); //back to ajax
    	die;
	}
}